package com.beanbean.record;

import android.os.Environment;

import java.io.File;
import java.util.List;

public class FileUtil {

    public static boolean isFile(String path) {
        return path != null && new File(path).isFile();
    }

    public static boolean isFile(File file) {
        return file != null && file.isFile();
    }

    public static String getFileAbsolutePath(String name) {
        return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "audio_record" + File.separator + name;
    }

    public static String getDirPath(){
        return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "audio_record";
    }

    public static File createFile(String name) {
        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "audio_record";
        File cacheDir = new File(path);
        if (!cacheDir.exists()) {
            cacheDir.mkdirs();
        }
        return new File(cacheDir, name);
    }

    public static void clearFilePathsList(List<String> filePathList) {
        for (int i = 0; i < filePathList.size(); i++) {
            File file = new File(filePathList.get(i));
            if (file.exists()) {
                file.delete();
            }
        }
    }

    public static void clearFilesList(List<File> filePathList) {
        if (filePathList == null || filePathList.size() == 0) {
            return;
        }
        for (File file : filePathList) {
            file.delete();
        }
        filePathList.clear();
    }
}
